-
Notifications
You must be signed in to change notification settings - Fork 2
/
Vfwprintf.c
110 lines (90 loc) · 3.19 KB
/
Vfwprintf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*++
toro C Library
https://github.com/KilianKegel/toro-C-Library#toro-c-library-formerly-known-as-torito-c-library
Copyright (c) 2017-2024, Kilian Kegel. All rights reserved.
SPDX-License-Identifier: GNU General Public License v3.0
Module Name:
Vfwprintf.c
Abstract:
Implementation of the Standard C function.
Write formatted output using a pointer to a list of arguments.
Author:
Kilian Kegel
--*/
#include <stdio.h>
#include <wchar.h>
#include <cde.h>
#include <CdeServices.h>
extern void* __cdeGetAppIf(void);
static void __fputcpp(int b, void** pstream)
{
CDEFILE* pCdeFile = *pstream;
if (O_TEXT == (pCdeFile->openmode & O_TEXT))
fputc(b, *pstream);
else
fputwc((wchar_t)b, *pstream);
}
/**
Synopsis
#include <wchar.h>
int vfwprintf(FILE* stream, const wchar_t* pszFormat, va_list ap);
Description
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/vfprintf-vfprintf-l-vfwprintf-vfwprintf-l?view=msvc-160
Parameters
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/vfprintf-vfprintf-l-vfwprintf-vfwprintf-l?view=msvc-160#parameters
Returns
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/vfprintf-vfprintf-l-vfwprintf-vfwprintf-l?view=msvc-160#return-value
**/
int vfwprintf(FILE* stream, const wchar_t* pszFormat, va_list ap) {
ROMPARM_VWXPRINTF RomParm = { \
/*fForceToDataSeg */ 1 ,\
/*fPointerIsParm */ 0 ,\
/*fPointerIsFilePointer */ 1 ,\
/*fCountIsParm; */ 0 ,\
/*fAjustDifference */ 0 ,\
/*fWide */ 1 ,\
/*fUEFIFormat */ 0, \
};
int nRet = 0;
CDE_APP_IF* pCdeAppIf = __cdeGetAppIf();
if (NULL == pCdeAppIf)
errno = EPERM;
else do
{
_PUTCHAR* pfnOutput = NULL;
if (CDEDBGMAGIC == (size_t)stream)
{
pfnOutput = pCdeAppIf->pCdeServices->pPutDebug;
}
else
{
switch (pCdeAppIf->DriverParm.CommParm.OSIf)
{
case PEIIF:
case DXEIF:
case SMMIF:
if ( (FILE*)CDE_STDOUT == stream
|| (FILE*)CDE_STDERR == stream)
pfnOutput = pCdeAppIf->pCdeServices->pPutConOut;
stream = (void*)pCdeAppIf;
break;
default:
pfnOutput = __fputcpp;
break;
}
}
nRet = (int)pCdeAppIf->pCdeServices->pVwxPrintf(
pCdeAppIf, // this
&RomParm, // IN ROMPARM_VWXPRINTF *pRomParm,
pszFormat, // IN const void *pszFormat,
pfnOutput, // void (*pfnDevPutChar)(UINT16/*wchar_t*/c,void** ppDest/*address of pDest*/),
stream, // UINT8 *pDest, pointer for the output function memory address or pCdeAppIf
(unsigned)-1, // unsigned dwCount,
ap // IN va_list ap
);
if (stdout == stream) {
pCdeAppIf->pCdeServices->pPutConOut(EOF, (void**)&pCdeAppIf); //flush to stdout
}
} while (0);
return nRet;
}